import collections
import os, sys
try:
    import openpyxl
except:
    os.system('pip3 install openpyxl --user')
    import openpyxl

def main(arg1, arg2=29, arg3=2):
    # arg3   blank lines before start lines

    s1 = open(arg1, mode='r', encoding='utf16')
    s2 = s1.read()
    s3 = s2.split('\n')[1]
    s4 = s3.split(' ')

    s5 = int(arg2)
    s12 = int(arg3)
    s6 = []

    for i in range(s5):
        s7 = i // 26
        if s7 == 0: s7s1 = ''
        else: s7s1 = chr(ord('A')+s7-1)
        s8 = chr(ord('A') + i%26)
        s6.append("%s%s" %(s7s1, s8))

    # s4    ['A1A4B4', 'B5', 'B1', '.', ..., '']
    # s6    ['A','B', ..., 'Z', 'AA', 'AB', ...]

    s10 = openpyxl.Workbook()
    s11 = s10['Sheet']
    for i in s6:
        s11.column_dimensions[i].width = 4
    s9 = {0:'', 1:'', 2:''}

    ii = 0
    for i in s4:
        if i != '.' and i != '':
            for i1 in range(len(i)//2):
                s9[ord(i[i1*2])-ord('A')] = ''.join(map(str,(s9[ord(i[i1*2])-ord('A')], i[i1*2+1])))
            for i2 in s9.keys():
                s11[''.join(map(str,(s6[ii%s5], (ii//s5)*4+i2+s12+1)))] = s9[i2]
            s9 = {0:'', 1:'', 2:''}
            ii +=1
    
    if s12 !=0:
        s11[s6[len(s6)//2]+str(s12//2)] = '.'.join(os.path.basename(arg1).split('.')[:-1])
    s10.save('.'.join(os.path.basename(arg1).split('.')[:-1])+'.xlsx')
    print("\t( %s Rows, %s Blank Lines ) %s" %(arg2, arg3, '.'.join(os.path.basename(arg1).split('.')[:-1])+'.xlsx'))

if __name__ == "__main__":
    if len(sys.argv)>=2:
        main(*sys.argv[1:])
    else:
        print('\tpython3 *this [*file(*txt)] [rows] [blank lines]')